package com.zqh.orderitemsave.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zqh.myfmmall.entity.OrderItem;
import com.zqh.myfmmall.result.Result;
import com.zqh.myfmmall.rowbeans.entity.ProductSku;
import com.zqh.orderitemsave.service.OrderItemSaveService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description :
 * @Author :kono淇杭哒、
 * @Create 2022-02-18 2:15
 */
@RestController
@RequestMapping("orderItem")
public class OrderItemSaveController{
    @Resource
    private OrderItemSaveService orderItemSaveService;

    @PostMapping("create")
    public Result create(@RequestBody OrderItem orderItem){
        return orderItemSaveService.save(orderItem) ? Result.success(null) : Result.internalServerError("服务器开小差了，请重试");
    }

    /*@PostMapping("createBatch")
    public Result createBatch(@RequestBody String orderItemsJsonString) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, OrderItem.class);
        List<OrderItem> orderItems = objectMapper.readValue(orderItemsJsonString, javaType);
        return orderItemSaveService.saveBatch(orderItems) ? Result.success(null) : Result.internalServerError("服务器开小差了，请重试");
    }*/

    @PostMapping("createBatch")
    public Result createBatch(@RequestBody List<OrderItem> orderItems){
        return orderItemSaveService.saveBatch(orderItems) ? Result.success() : Result.internalServerError();
    }

    @PostMapping("orderItem/saveBatch")
    Result updateBatch(@RequestBody List<OrderItem> orderItems){
        return orderItemSaveService.saveBatch(orderItems) ? Result.success() : Result.internalServerError();
    }

}
